/**
 * Created by George on 2018/1/28.
 * frame route
 */

import polyfill from "../common/polyfill"
import mainCtrl from "./mainCtrl"
import activityCtrl from "../activity/activityCtrl"
import createActivityCtrl from "../activity/createActivityCtrl"
import editActivityCtrl from "../activity/editActivityCtrl"
import createDuesCtrl from "../dues/createDuesCtrl"
import duesCtrl from "../dues/duesCtrl"
import editDuesCtrl from "../dues/editDuesCtrl"
import createNoteCtrl from "../note/createNoteCtrl"
import noteCtrl from "../note/noteCtrl"
import editNoteCtrl from "../note/editNoteCtrl"
import createUserCtrl from "../user/createUserCtrl"
import userCtrl from "../user/userCtrl"
import editUserCtrl from "../user/editUserCtrl"
import paginationDirective from "../components/paginationDirective"

// frameRouter.js

function frameRouter() {

    polyfill();

    var appNote = angular.module('appNote', ['ui.router']);

    appNote.controller("mainCtrl", mainCtrl);
    appNote.controller("activityCtrl", activityCtrl);
    appNote.controller("createActivityCtrl", createActivityCtrl);
    appNote.controller("editActivityCtrl", editActivityCtrl);
    appNote.controller("createDuesCtrl", createDuesCtrl);
    appNote.controller("duesCtrl", duesCtrl);
    appNote.controller("editDuesCtrl", editDuesCtrl);
    appNote.controller("createNoteCtrl", createNoteCtrl);
    appNote.controller("noteCtrl", noteCtrl);
    appNote.controller("editNoteCtrl", editNoteCtrl);
    appNote.controller("createUserCtrl", createUserCtrl);
    appNote.controller("userCtrl", userCtrl);
    appNote.controller("editUserCtrl", editUserCtrl);

    appNote.filter('trustHtml', function ($sce) {

        return function (input) {
            return $sce.trustAsHtml(input);
        }

    });

    appNote.directive('pageDirective', paginationDirective);

    appNote.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
    }]).config(['$stateProvider', '$urlRouterProvider', '$controllerProvider', function ($stateProvider, $urlRouterProvider, $controllerProvider) {
        $urlRouterProvider.when("", "/user");
        $urlRouterProvider.otherwise("/user");
        $stateProvider.state("activity", {
            url: '/activity',
            templateUrl: 'views/activity/activity.html',
            controller: 'activityCtrl'
        }).state("editActivity", {
            url: '/activity/edit/{activityId:.*}',
            templateUrl: 'views/activity/editActivity.html',
            controller: 'editActivityCtrl'
        }).state("createActivity", {
            url: '/activity/create',
            templateUrl: 'views/activity/createActivity.html',
            controller: 'createActivityCtrl'
        }).state("dues", {
            url: '/dues',
            templateUrl: 'views/dues/dues.html',
            controller: 'duesCtrl'
        }).state("editDues", {
            url: '/dues/edit/{duesId:.*}',
            templateUrl: 'views/dues/editDues.html',
            controller: 'editDuesCtrl'
        }).state("createDues", {
            url: '/dues/create',
            templateUrl: 'views/dues/createDues.html',
            controller: 'createDuesCtrl'
        }).state("user", {
            url: '/user',
            templateUrl: 'views/user/user.html',
            controller: 'userCtrl'
        }).state("editUser", {
            url: '/user/edit/{userId:.*}',
            templateUrl: 'views/user/editUser.html',
            controller: 'editUserCtrl'
        }).state("createUser", {
            url: '/user/create',
            templateUrl: 'views/user/createUser.html',
            controller: 'createUserCtrl'
        }).state("note", {
            url: '/note',
            templateUrl: 'views/note/note.html',
            controller: 'noteCtrl'
        }).state("createNote", {
            url: '/note/create',
            templateUrl: 'views/note/createNote.html',
            controller: 'createNoteCtrl'
        }).state("editNote", {
            url: '/note/edit/{noteId:.*}',
            templateUrl: 'views/note/editNote.html',
            controller: 'editNoteCtrl'
        });
    }]);

    angular.element(document).ready(function () {
        angular.bootstrap(document.body, ['appNote']);
    });

}

export default frameRouter;